<?php
class AdmContent {

      public function showHtml(){
          //recuperar node pelo id com nodeDAO
       echo
        '
         <div class="content">

            <div class="content_box">'.$this->showTaxo().

         ' </div>

        </div>

        <div class="cleaner"></div>
    </div><!-- End of Content -->
        ';
    }

    public function showTaxo(){
        $nodeDao = new NodeDao();

        if(SessionManager::isLogged()==FALSE){
          echo '<center><h5>Sessão inválida, você será redirecionado para a área pública em 5 segundos</h5></center>';
          echo '<meta HTTP-EQUIV=\'Refresh\' CONTENT=\'5;URL='.Config::$domainName.'/Application.php\'>';
          return;
        }

        if(Config::$option != 0){
            return $this->showContent();
        }
        if(Config::$current==0){
            return;
        }

        require_once('../DAO/mySqlConnect.php'); // create the mySqlConnect class
        $mySqlConnect = new MySqlConnect();
        $taxo = NodeDao::db_node_by_id($mySqlConnect->getLinkDB(), Config::$current);

        if(SessionManager::getBySession('read')==0){
            echo "<h5>Seu nível de acesso não permite requerer informações do banco de dados, favor contatar
                administrador para regularizar o seu acesso</h5>";
            return;
        }


        $string = '<table>';
        $string = $string.'<tr>';
        $string = $string.'<td><center><h3>';
        $string = $string.$taxo->taxo->taxo.' '.$taxo->taxo->nome;
        $string = $string.'</h3></center></td>';
        $string = $string.'</tr>';

        $string = $string.'<tr>';
        $string = $string.'<td><center>';
        $string = $string.$taxo->taxo->descricao;
        $string = $string.'</center></td>';
        $string = $string.'</tr>';
            
        $string = $string.'</table>';

        $string = $string.'<br/>';

        EspecieDao::init();
        EspecieDao::getSonEspecies($mySqlConnect->getLinkDB(),$taxo->id);

        if(EspecieDao::$Arr->count()>0){
            $string = $string.'<h5>Listagem de Todas as Espécies</h5>';
        }

        if (isset ($_GET['qtdLinhas'])){
            Config::$qtdeLinhas = $_GET['qtdLinhas'];
         }

         if(isset ($_GET['primeiraLinha'])){
             Config::$primeiraLinha = $_GET['primeiraLinha'];
         }
         if(isset ($_GET['ultimaLinha'])){
             Config::$ultimaLinha = $_GET['ultimaLinha'];
         }

        $string = $string.'<form action="'.Config::$domainName.'/Administracao/Administracao.php" method="GET">
            Qtde de Linhas:'.$this->getQtdLinhas().'
            
            <input type="submit"/> <br /><br /><br />
            </form> ';

        $string = $string.'<div class="tblDiv"><table align="center" border="1">
        <tr>
        <td>
        <form action="'.Config::$domainName.'/Administracao/Administracao.php" method="GET">';
        if (isset ($_GET['filtro'])){
            $string = $string.'Nome: <input type="text" value="'.$_GET['filtro'].'" name="filtro"  /></form><br /></td></tr>';
        }else{
            $string = $string.'Nome: <input type="text" name="filtro"  /> </form><br /></td></tr>';

        }


          $iterator = EspecieDao::$Arr->getIterator();

          if (isset($_GET['filtro'])){
            $iterator =  EspecieDao::buscarEspecies($mySqlConnect->getLinkDB(),$_GET['filtro']);

          }
         

         if (isset ($_GET['indexar'])){
            if ($_GET['indexar']==0) {
              if (Config::$primeiraLinha > 0){
                Config::$ultimaLinha = (Config::$ultimaLinha - Config::$qtdeLinhas);
                Config::$primeiraLinha = (Config::$primeiraLinha - Config::$qtdeLinhas);
              }
            }else{
              
                 Config::$primeiraLinha = (Config::$primeiraLinha + Config::$qtdeLinhas);
                 
              
            }

        }


        

        $numLinhas = 0 ;
        while($iterator->valid()) {
            if (($numLinhas < Config::$qtdeLinhas)  ){
                Config::$ultimaLinha = (Config::$primeiraLinha + Config::$qtdeLinhas);
                if(($iterator->key() >= Config::$primeiraLinha) && ($iterator->key() <= Config::$ultimaLinha)){

                $current = $iterator->current();
                $string = $string.'<tr>';
                $string = $string.'<td>';
                $string = $string.'<a style="color:#FFFF99;" href="'.Config::$domainName.'/Administracao/Administracao.php?option=15&idpai='.$current->id.'">'.$current->nome.'</a>';
                $string = $string.'</td>';
                if(SessionManager::getBySession('update')==1){
                $string = $string.'<td>';
                $string = $string.'<a style="color:#FFFF99;" href="'.Config::$domainName.'/Administracao/Administracao.php?option=10&idpai='.$current->id.'">editar</a>';
                $string = $string.'</td>';
                }if(SessionManager::getBySession('delete')==1){
                $string = $string.'<td>';
                $string = $string.'<a style="color:#FFFF99;" href="'.Config::$domainName.'/Administracao/Administracao.php?option=11&idpai='.$current->id.'">excluir</a>';
                $string = $string.'</td>';
                }
                $string = $string.'</tr>';

                $numLinhas++;
                }
            }else{
                break;
            }

            
            $iterator->next();
               
           }
        $string = $string.'</table></div>';

      
        $string = $string.'
            <a href="'.Config::$domainName.'/Administracao/Administracao.php?indexar=0&qtdLinhas='.Config::$qtdeLinhas.'&primeiraLinha='.Config::$primeiraLinha.'"><<< Anterior </a>
            <a href="'.Config::$domainName.'/Administracao/Administracao.php?indexar=1&qtdLinhas='.Config::$qtdeLinhas.'&primeiraLinha='.Config::$primeiraLinha.'">Próximo >>> </a>
        ';

        $string = $string.'<h5>Esta classificação tem '.$this->showSon($taxo,$mySqlConnect->getLinkDB()).' espécies</h5>';
        if(SessionManager::getBySession('create')==1){
        $string = $string. '<h5><a href="'.Config::$domainName.'/Administracao/Administracao.php?idpai='.$taxo->id.'&option=3">Cadastrar SubTaxo
            </a></h5>';
        }
        if(Config::$current>1){
           if(SessionManager::getBySession('update')==1){
           $string = $string. '<h5><a href="'.Config::$domainName.'/Administracao/Administracao.php?idpai='.$taxo->id.'&option=6">Editar Taxo
            </a></h5>';
           }if(SessionManager::getBySession('delete')==1){
            $string = $string. '<h5><a href="'.Config::$domainName.'/Administracao/Administracao.php?idpai='.$taxo->id.'&option=7">Excluir Taxo
            </a></h5>';
           }if(SessionManager::getBySession('create')==1){
             $string = $string. '<h5><a href="'.Config::$domainName.'/Administracao/Administracao.php?idpai='.$taxo->id.'&option=13">Cadastrar Uma Espécie a este Taxo
            </a></h5>';
           }if(SessionManager::getBySession('update')==1 && $this->numEspecies($taxo->id)>0){
            $string = $string. '<h5><a href="'.Config::$domainName.'/Administracao/Administracao.php?idpai='.$taxo->id.'&option=12">Especificar a espécie de uma categoria superior
            </a></h5>';
            }
        }

        $mySqlConnect->closeDB();
        return $string;

    }

    public function showSon($taxo,$mysql) {
        NodeDao::$son=0;
        NodeDao::$flag=false;
        NodeDao::getSonNumber($mysql, $taxo->id);
        return NodeDao::$son;
    }

    public function getQtdLinhas(){
        $string = '<select name="qtdLinhas">';
        $values = array(1,5,10,15,20);
        foreach ($values as $qtd){
            if($qtd == Config::$qtdeLinhas)
                $string = $string.'<option value="'.$qtd.'" selected="true">'.$this->twoDigits($qtd).'</option>';
            else
                $string = $string.'<option value="'.$qtd.'">'.$this->twoDigits($qtd).'</option>';
        }

        $string = $string.'</select>';
        return $string;
    }

    public function twoDigits($num){
        if($num<10){
            return '0'.$num;
        }
        return $num;
    }
    

    public function showContent(){
        if(Config::$option==5){
            SessionManager::destroy();
            echo '<meta HTTP-EQUIV=\'Refresh\' CONTENT=\'0;URL='.Config::$domainName.'/Application.php\'>';
        }
        if(Config::$option==12){
            $mysql = new mySqlConnect();
            $string=
            '<h2>Vincular uma Espécie</h2>

                <fieldset>
                    <legend><h5>Formulário de vinculação</h5> </legend>


                <form action="./Administracao.php?idpai='.Config::$idpai.'&current='.Config::$idpai.'" method="POST">
                    <dl>
                        <dd>Espécie:</dd>
                        <dt>'.$this->showPossibleEspecies($mysql->getLinkDB(),Config::$idpai)
                        .'</dt>
                    </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="vincular"/></dt>
                    </dl>
                </form>

                </fieldset>';
            $mysql->closeDB();
            return $string;
        }
        if(Config::$option==3){
            $string=
            '<h2>Cadastrar Taxo</h2>

                <fieldset>
                    <legend><h5>Formulário de Cadastro</h5> </legend>


                <form action="./Administracao.php?idpai='.Config::$idpai.'&current='.Config::$idpai.'" method="POST">
                    <dl>
                        <dd>Taxo:</dd>
                        <dt>'.$this->showPossibleTaxos(false)
                        .'</dt>
                    </dl>

                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="name"/></dt>
                    </dl>

                    <dl>
                        <dd>Descrição:</dd>
                        <dt> <textarea name="descricao"></textarea> </dt>
                    </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="enviar"/></dt>
                    </dl>
                </form>

                </fieldset>';
            return $string;
        }if(Config::$option==6){
            $mysql = new mySqlConnect();
            $current = NodeDao::db_node_by_id($mysql->getLinkDB(), Config::$idpai);
            $mysql->closeDB();
            $string=
            '<h2>Editar Taxo</h2>

                <fieldset>
                    <legend><h5>Formulário de Edição</h5> </legend>


                <form action="./Administracao.php?idpai='.Config::$idpai.'&current='.Config::$idpai.'" method="POST">
                    <dl>
                        <dd>Taxo:</dd>
                        <dt>'.$this->showPossibleTaxos(true)
                        .'</dt>
                    </dl>

                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="name" value="'.$current->taxo->nome.'"/></dt>
                    </dl>

                    <dl>
                        <dd>Descrição:</dd>
                        <dt> <textarea name="descricao">'.$current->taxo->descricao.'</textarea> </dt>
                    </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="editar"/></dt>
                    </dl>
                </form>

                </fieldset>';
            return $string;
        } if(Config::$option==2){
            $string =
                '
                <h2>Cadastrar Usuário</h2>

                <fieldset>
                    <legend><h5>Formulário de Cadastro</h5> </legend>


                <form action="./Administracao.php" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome"/></dt>
                    </dl>

                    <dl>
                        <dd>Login:</dd>
                        <dt> <input type="text" name="login"/></dt>
                    </dl>

                    <dl>
                        <dd>Senha:</dd>
                        <dt> <input type="password" name="senha"/></dt>
                    </dl>

                    <dl>
                        <dd>Pode Cadastrar?</dd>
                        <dt> <input type="checkbox" value="sim" name="create"/></dt>
                    </dl>

                    <dl>
                        <dd>Pode Requerer?</dd>
                        <dt> <input type="checkbox" value="sim" name="read"/></dt>
                    </dl>

                    <dl>
                        <dd>Pode Atualizar?</dd>
                        <dt> <input type="checkbox" value="sim" name="update"/></dt>
                    </dl>

                    <dl>
                        <dd>Pode Excluir?</dd>
                        <dt> <input type="checkbox" value="sim" name="delete"/></dt>
                    </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="cadastrar"/></dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        } if(Config::$option==4){
            $mysql = new mySqlConnect();
            UserDao::initUsuario();
            $current = UserDao::db_user_by_id($mysql->getLinkDB(), Config::$idpai);
            $string =
                '
                    	<h2>Editar Usuário</h2>

                <fieldset>
                    <legend><h5>Formulário de Edição</h5> </legend>


                <form action="./Administracao.php" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome" value="'.$current->nome.'"/></dt>
                    </dl>

                    <dl>
                        <dd>Login:</dd>
                        <dt> <input type="text" name="login" value="'.$current->login.'"/></dt>
                    </dl>

                   '.$this->showSenha($current).'

                    <dl>
                        <dt> <input type="hidden" name="id" value="'.$current->id.'"/></dt>
                    </dl>

                    '.$this->showEdit($current).'

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="edit"/></dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        } if(Config::$option==7){
            $mysql = new mySqlConnect();
            NodeDao::delete($mysql->getLinkDB(), Config::$idpai);
            $mysql->closeDB();
        }if(Config::$option==11){
            $mysql = new mySqlConnect();
            EspecieDao::init();
            EspecieDao::delete($mysql->getLinkDB(), Config::$idpai);
            $mysql->closeDB();
        }if(Config::$option==8){
            $string =
                '
                 <h2>Cadastrar Espécie</h2>

                <fieldset>
                    <legend><h5>Formulário de Cadastro</h5> </legend>


                <form action="./Administracao.php" enctype="multipart/form-data" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome"/></dt>
                    </dl>

                    <dl>
                        <dd>Porte:</dd>
                        <dt> <input type="text" name="porte"/></dt>
                    </dl>

                    <dl>
                        <dd>Localidade:</dd>
                        <dt> <input type="text" name="localidade"/></dt>
                    </dl>

                    <dl>
                        <dd>Descrição:</dd>
                        <dt> <textarea name="descricao"></textarea> </dt>
                    </dl>

                  <dl>
                        <dd>Imagem</dd>
                        <dt> <input id="img" type="file" name="img"/></dt>
                   </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="especie" value="Cadastrar Espécie"/></dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        }if(Config::$option==13){
            $string =
                '
                 <h2>Cadastrar Espécie</h2>

                <fieldset>
                    <legend><h5>Formulário de Cadastro</h5> </legend>


                <form action="./Administracao.php?idpai='.Config::$idpai.'&current='.Config::$idpai.'"  enctype="multipart/form-data" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome"/></dt>
                    </dl>

                    <dl>
                        <dd>Porte:</dd>
                        <dt> <input type="text" name="porte"/></dt>
                    </dl>

                    <dl>
                        <dd>Localidade:</dd>
                        <dt> <input type="text" name="localidade"/></dt>
                    </dl>

                       <dl>
                        <dd>Descrição:</dd>
                        <dt> <textarea name="descricao"></textarea> </dt>
                    </dl>

                  <dl>
                        <dd>Imagem</dd>
                        <dt> <input type="file" name="img"/></dt>
                   </dl>

                    <dl>
                        <dd></dd>
                        <dt> <input type="submit" name="especiePai" value="Cadastrar Espécie"/></dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        }if(Config::$option==10){
            EspecieDao::init();
            $mysql = new mySqlConnect();
            $especie = EspecieDao::db_especie_by_id($mysql->getLinkDB(), Config::$idpai);
            $string =
                '
                 <h2>Editar Espécie</h2>

                <fieldset>
                    <legend><h5>Formulário de Edição</h5> </legend>


                <form action="./Administracao.php?option=15&idpai='.Config::$idpai.'" enctype="multipart/form-data" method="POST">
                    <dl>
                        <dd>Nome:</dd>
                        <dt> <input type="text" name="nome" value="'.$especie->nome.'"/></dt>
                    </dl>

                    <dl>
                        <dd>Porte:</dd>
                        <dt> <input type="text" name="porte" value="'.$especie->porte.'"/></dt>
                    </dl>

                    <dl>
                        <dd>Localidade:</dd>
                        <dt> <input type="text" name="localidade" value="'.$especie->localidade.'"/></dt>
                    </dl>

                       <dl>
                        <dd>Descrição:</dd>
                        <dt> <textarea name="descricao">'.$especie->descricao.'</textarea> </dt>
                    </dl>

                  <dl>
                        <dd>Imagem</dd>
                        <dt> <input type="file" name="img"/><h5 style="font-size:0.8em;margin-left:10px;">se vazio continua a imagem anterior</h5></dt>
                   </dl>
                         <input type="hidden" name="vincula" value="'.Config::$idpai.'"/>
                    <dl>
                        <dd></dd>
                        <dt>
                            <input type="submit" name="especiedit" value="Editar Espécie"/>
                            <input type="submit" name="especierev" value="Resetar Classificação de Espécie"/>
                        </dt>
                    </dl>
                </form>

                </fieldset>
                ';
            return $string;
        }if(Config::$option==9){
            $mysql = new mySqlConnect;
            UserDao::initUsuario();
            $iterator = UserDao::getAll($mysql->getLinkDB())->getIterator();
            $string = '';
            $string = $string.'<center><h5>Listagem de Todos os Usuários</h5><div class="tblDiv">
             <table align="center" border="1">';
            while($iterator->valid()){
                $current = $iterator->current();
                $string = $string.'<tr>';
                $string = $string.'<td>';
                $string = $string.$current->nome;
                $string = $string.'</td>';
                $string = $string.'<td>';
                $string = $string.$current->login;
                $string = $string.'</td>';
                if(SessionManager::getBySession('update')==1){
                $string = $string.'<td>';
                $string = $string.'<a href="'.Config::$domainName.'/Administracao/Administracao.php?option=4&idpai='.$current->id.'">editar</a>';
                $string = $string.'</td>';
                }if(SessionManager::getBySession('delete')==1){
                $string = $string.'<td>';
                $string = $string.'<a href="'.Config::$domainName.'/Administracao/Administracao.php?option=14&idpai='.$current->id.'">excluir</a>';
                $string = $string.'</td>';
                }
                $string = $string.'</tr>';
                $iterator->next();
            }
            $string = $string.'</table></div></center>';
            $mysql->closeDB();
            return $string;
        }if(Config::$option==14){
            $mysql = new mySqlConnect();
            UserDao::deleteUserById($mysql->getLinkDB(), Config::$idpai);
            $mysql->closeDB();
        }if(Config::$option==15){
            $mysql = new mySqlConnect();
            EspecieDao::init();
            $temp = EspecieDao::db_especie_by_id($mysql->getLinkDB(), Config::$idpai);
            $mysql->closeDB();
            return $this->showEspecie($temp);
            
        }


    }

    public function showEspecie($temp){
            $string='<h2>'.$temp->nome.'</h2></br>';
         if($temp->img!=null){
            
                $str = explode('/', $temp->img);
                $str = array_reverse($str);
                $src='';
                for($i = 0;$i<3;$i++){
                        $src = '/'.$str[$i].$src;
                }

             $string = $string.'<img class="image_wrapper image_fl" src="'.Config::$domainName.$src.'" width=200 height=200>';
         
         }else{
                $string = $string.'<img class="image_wrapper image_fl" src="'.Config::$domainName.'/Administracao/images/imagem_indisponivel.jpg" width=200 height=200>';
         }
        
        
            $string = $string.'<div>';
            $string = $string.'<h5>Porte: ';
            $string = $string.'<span style="font-size:0.9em;">'.$temp->porte.'</span></h5><br/>';
            $string = $string.'<h5>Localidade: ';
            $string = $string.'<span style="font-size:0.9em;">'.$temp->localidade.'</span></h5><br/>';
        
            //$string = $string.'<div class="cleaner h30"></div>';
            $string = $string.'<p>'.$temp->descricao.'</p><br/>';
            $string = $string.'</div>';
            $string = $string.'<div class="cleaner h30"></div>';
            
            $string = $string.'<div style="float:right;margin-right:20%;"><h5>';
             if(SessionManager::getBySession('update')==1)
                   $string = $string.'<a style="margin-right:20%;" href="'.Config::$domainName.'/Administracao/Administracao.php?option=10&idpai='.$temp->id.'">editar</a>';
             if(SessionManager::getBySession('delete')==1)
                $string = $string.'<a style="margin-right:20%;" href="'.Config::$domainName.'/Administracao/Administracao.php?option=11&idpai='.$temp->id.'">excluir</a>';

             $string = $string.'</h5></div>';
            return $string;
    }

    public function showPossibleTaxos($edit){
         require_once('../DAO/mySqlConnect.php'); // create the mySqlConnect class
        $mySqlConnect = new MySqlConnect();
        $taxo = NodeDao::db_node_by_id($mySqlConnect->getLinkDB(), Config::$idpai);

        $nivel=0;

        $niveis = array( 1 => array( 'Reino' ),
                                    2 =>array('Subreino','Infra-reino'),
                                    3 =>array('Filo'),
                                    4 =>array( 'Subfilo','Infrafilo','Microfilo'),
                                    5 => array('Classe'),
                                    6 => array('Subclasse','Infraclasse'),
                                    7 => array  ('Ordem'),
                                    8 => array('Subordem','Infraordem'),
                                    9 => array('Familia'),
                                    10 => array('Subfamilia'),
                                    11 => array('Genero'),
                                    12 =>array( 'Subgenero'),
                                    13 =>  array('Especie'),
                                    14 => array( 'Subespecie', 'Infraespecie')  ) ;

        for ($i=1;$i<=14;$i++){
             foreach ( $niveis[$i]  as $string   ){

                 //echo $string.' | '.$taxo->taxo->taxo.'</br>';
                 
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0){
                    $nivel = $i;
                 }
             }
         }

         $str = '<select name="taxo">';
         if($edit){
             if($nivel % 2 !=0){
                  $nivel--;
             }
         }else{
              $str = $str.'<option selected="true">Escolha uma categoria:</option>';
         }

         if($nivel==0){
              $str = $str.'<option>Reino</option> ';
         }

         if($nivel==1){
             foreach ( $niveis[2]  as $string   ){
                if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }

             foreach ( $niveis[3]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==2){
             foreach ( $niveis[2]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[3]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==3){
             foreach ( $niveis[4]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[5]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==4){
             foreach ( $niveis[4]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[5]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==5){
             foreach ( $niveis[6]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[7]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==6){
             foreach ( $niveis[6]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[7]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==7){
             foreach ( $niveis[8]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[9]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==8){
             foreach ( $niveis[8]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[9]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==9){
             foreach ( $niveis[10]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[11]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==10){
             foreach ( $niveis[10]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[11]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==11){
             foreach ( $niveis[12]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[13]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }
         if($nivel==12){
             foreach ( $niveis[13]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
             foreach ( $niveis[14]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }
             }
         }if($nivel==13){
             foreach ( $niveis[14]  as $string   ){
                 if(strcasecmp($string, trim( $taxo->taxo->taxo)) == 0 && $edit){
                    $str = $str.'<option selected="true">'.$string.'</option> ';
                }else{
                    $str = $str.'<option>'.$string.'</option> ';
                }        
             }
         }
  
            $str = $str.'</select>';

        return $str;
    }

    public function showPossibleEspecies($dbc,$id) {
        require '../dinamic/especie.php';
        $especie = NodeDao::db_node_by_id($dbc, $id);  

        $pai = $especie->father;


        $iterator = EspecieDao::getEspecies($dbc,$pai->id);

        $string='<select name="vincula">';
        
        $string = $string.'<option selected="true">Escolha uma espécie</option>';
        
        while($iterator->valid()){
            $string = $string.'<option value="'.$iterator->current()->id.'">'.$iterator->current()->nome.'</option>';
            $iterator->next();
        }
        $string = $string.'</select>';
        return $string;
    }

    public function numEspecies($id){
        $mysql = new mySqlConnect();
        $especie = NodeDao::db_node_by_id($mysql->getLinkDB(), $id);

        $pai = $especie->father;


        $iterator = EspecieDao::getEspecies($mysql->getLinkDB(),$pai->id);
        $mysql->closeDB();
        return $iterator->count();

    }

    public function  showSenha($current){
        if($current->id == SessionManager::getBySession('id')){
            return  '<dl>
                        <dd>Nova Senha:</dd>
                        <dt> <input type="password" name="senha" /><h5 style="font-size:0.8em;margin-left:10px;">se vazio continua a senha anterior</h5></dt>
                    </dl>';
        }
        return;
    }

    public function showEdit($current){
        $string = "";

        if(SessionManager::getBySession('update')==1){
            if($current->create==1){
            $string = $string.
                   '<dl>
                        <dd>Pode Cadastrar?</dd>
                        <dt> <input type="checkbox" value="sim" name="create" checked=checked/></dt>
                    </dl>';
            }else{
                $string = $string.
                   '<dl>
                        <dd>Pode Cadastrar?</dd>
                        <dt> <input type="checkbox" value="sim" name="create"/></dt>
                    </dl>';
            }
            if($current->read==1){
                 $string = $string.
                    '<dl>
                        <dd>Pode Requerer?</dd>
                        <dt> <input type="checkbox" value="sim" name="read" checked=checked/></dt>
                    </dl>';
            }else{
                $string = $string.
                    '<dl>
                        <dd>Pode Requerer?</dd>
                        <dt> <input type="checkbox" value="sim" name="read"/></dt>
                    </dl>';
            }$string = $string.
                    '<dl>
                        <dd>Pode Atualizar?</dd>
                        <dt> <input type="checkbox" value="sim" name="update" checked=checked/></dt>
                    </dl>';
            if($current->delete==1){
                $string = $string.
                   ' <dl>
                        <dd>Pode Excluir?</dd>
                        <dt> <input type="checkbox" value="sim" name="delete" checked=checked/></dt>
                    </dl>';
            }else{
                 $string = $string.
                   ' <dl>
                        <dd>Pode Excluir?</dd>
                        <dt> <input type="checkbox" value="sim" name="delete"/></dt>
                    </dl>';
            }
            
            return $string;
        }
    }
}
?>
